package com.itfenghuang.day16_lx;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class A02_视频传输 {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(8080);
        while (true){
            Socket at = ss.accept();
            InputStream is = at.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String s = br.readLine();
            System.out.println(s);
            String[] xx = s.split(" ");
            String zz = xx[1];
            String zz1 = zz.substring(1);
            FileInputStream fis = new FileInputStream(zz1);
            OutputStream os = at.getOutputStream();
            os.write("HTTP/1.1 200 OK\r\n".getBytes());
            os.write("Content-Type:text/html\r\n".getBytes());
            os.write("\r\n".getBytes());
            byte[] bs = new byte[1024];
            int len;
            while ((len=fis.read(bs))!=-1){
                os.write(bs,0,len);
            }
            os.close();
            br.close();
         }

    }
}
